import HTTP from '../../../../utils/http';
import { API, API_GENERATE } from '../../../../config/api';

const ORDER_API_LIST = [{
	tCode: 'L',
	apiObj: {
		orderAddP: API.LONG_PUR_ORDER_ADD,//采购订单   新增/编辑
		orderAddS: API.LONG_SALE_ORDER_ADD,//销售订单  新增/编辑
		orderPlanList: API.LONG_DELIVERY_PLAN_LIST,//长约交货计划 列表
		orderPlanAdd: API.LONG_DELIVERY_PLAN_ADD,//长约交货计划   新增/编辑
		orderPlanDel: API.LONG_DELIVERY_PLAN_DEL,//长约交货计划   删除
	}
}, {
	tCode: 'E',
	apiObj: {
		orderAddP: API.EXCUTE_PUR_ORDER_ADD,//采购订单   新增/编辑
		orderAddS: API.EXCUTE_SALE_ORDER_ADD,//销售订单  新增/编辑
		orderPlanList: API.DELIVERY_PLAN_LIST,//交货计划 列表
		orderPlanAdd: API.DELIVERY_PLAN_ADD,//交货计划   新增/编辑
		orderPlanDel: API.DELIVERY_PLAN_DEL,//交货计划   删除
	}
}, {
	tCode: 'QH',
	apiObj: {
		orderAddP: API.EXCUTE_PUR_ORDER_ADD,//采购订单   新增/编辑
		orderAddS: API.EXCUTE_SALE_ORDER_ADD,//销售订单  新增/编辑
		orderPlanList: API.DELIVERY_PLAN_LIST,//交货计划 列表
		orderPlanAdd: API.DELIVERY_PLAN_ADD,//交货计划   新增/编辑
		orderPlanDel: API.DELIVERY_PLAN_DEL,//交货计划   删除
	}
}, {
	tCode: 'S',
	apiObj: {
		orderAddP: API.ORDINARY_PUR_ORDER_ADD,//采购订单   新增/编辑
		orderAddS: API.ORDINARY_SALE_ORDER_ADD,//销售订单  新增/编辑
		orderPlanList: API.DELIVERY_PLAN_LIST,//交货计划 列表
		orderPlanAdd: API.DELIVERY_PLAN_ADD,//交货计划   新增/编辑
		orderPlanDel: API.DELIVERY_PLAN_DEL,//交货计划   删除
	}
}, {
	tCode: 'F',
	apiObj: {
		orderAddP: API.FUTURE_PUR_ORDER_ADD,//采购订单   新增/编辑
		orderAddS: API.FUTURE_SALE_ORDER_ADD,//销售订单  新增/编辑
		orderPlanList: API.DELIVERY_PLAN_LIST,//交货计划 列表
		orderPlanAdd: API.DELIVERY_PLAN_ADD,//交货计划   新增/编辑
		orderPlanDel: API.DELIVERY_PLAN_DEL,//交货计划   删除
	}
}, {
	tCode: 'A',
	apiObj: {
		orderAddP: API.AGENT_ORDER_ADD,//采购订单   新增/编辑
		orderAddS: API.AGENT_ORDER_ADD,//销售订单  新增/编辑
		orderPlanList: API.DELIVERY_PLAN_LIST,//交货计划 列表
		orderPlanAdd: API.DELIVERY_PLAN_ADD,//交货计划   新增/编辑
		orderPlanDel: API.DELIVERY_PLAN_DEL,//交货计划   删除
	}
}, {
	tCode: 'C',
	apiObj: {
		orderAddP: API.CLOSE_ORDER_ADD,//采购订单   新增/编辑
		orderAddS: API.CLOSE_ORDER_ADD,//销售订单  新增/编辑
		orderPlanList: API.DELIVERY_PLAN_LIST,//交货计划 列表
		orderPlanAdd: API.DELIVERY_PLAN_ADD,//交货计划   新增/编辑
		orderPlanDel: API.DELIVERY_PLAN_DEL,//交货计划   删除
	}
}]

//请求
class OrderAPIService {
	initAPIs (tCode, orderType) {
		let orderAddName = orderType === 'P' ? 'orderAddP' : 'orderAddS';
		let apiList = {};
		ORDER_API_LIST.map(item => {
			if (item.tCode === tCode) {
				apiList.orderAdd = API_GENERATE(item.apiObj[orderAddName]);
				apiList.orderPlanList = API_GENERATE(item.apiObj.orderPlanList);
				apiList.orderPlanAdd = API_GENERATE(item.apiObj.orderPlanAdd);
				apiList.orderPlanDel = API_GENERATE(item.apiObj.orderPlanDel);
			}
		})
		//公共
		apiList.orderItemDel = API_GENERATE(API.ORDER_ITEM_DEL);
		apiList.orderItemAdd = API_GENERATE(API.ORDER_ITEM_ADD);
		apiList.orderItemList = API_GENERATE(API.ORDER_ITEM_LIST);

		apiList.orderFeeAdd = API_GENERATE(API.ORDER_FEE_ADD);
		apiList.orderFeeList = API_GENERATE(API.ORDER_FEE_LIST);

		apiList.orderMapAdd = API_GENERATE(API.ORDER_MAP_ADD);
		apiList.orderMapedList = API_GENERATE(API.ORDER_MAPED_LIST);
		apiList.orderCanMapList = API_GENERATE(API.ORDER_CAN_MAP_LIST);
		apiList.orderMapDel = API_GENERATE(API.ORDER_MAP_DEL);
		this.apiList = apiList;
	}

	//订单-新增/编辑
	orderAdd (params = {}, handleError) {
		return HTTP.POST(this.apiList.orderAdd, params, handleError)
	}

	//订单-详细信息
	getOrderDetail (params = {}, handleError) {
		return HTTP.POST(API_GENERATE(API.ORDER_DETAIL), params, handleError);
	}

	//商品-列表
	getGoodsList (params, handleError) {
		return HTTP.POST(this.apiList.orderItemList, params, handleError);
	}
	//商品-新增/编辑
	goodsAdd (params, handleError) {
		return HTTP.POST(this.apiList.orderItemAdd, params, handleError);
	}
	//商品-删除
	goodsDel (params, handleError) {
		return HTTP.POST(this.apiList.orderItemDel, params, handleError);
	}

	//交货计划-列表
	getDeliveryPlanList (params, handleError) {
		return HTTP.POST(this.apiList.orderPlanList, params, handleError);
	}
	//交货计划-新增/编辑
	deliveryPlanAdd (params, handleError) {
		return HTTP.POST(this.apiList.orderPlanAdd, params, handleError)
	}
	//交货计划-删除
	deliveryPlanDel (params, handleError) {
		return HTTP.POST(this.apiList.orderPlanDel, params, handleError)
	}

	//费用-列表
	getFeeList (params = {}, handleError) {
		return HTTP.POST(this.apiList.orderFeeList, params, handleError);
	}
	//费用-新增/编辑
	feeAdd (params = {}, handleError) {
		return HTTP.POST(this.apiList.orderFeeAdd, params, handleError);
	}

	//意向-列表
	getIntentionList (params, handleError) {
		return HTTP.POST(API_GENERATE(API.POTENTIAL_CLIENTS_LIST), params, handleError);
	}
	//意向-新增/编辑
	intentionAdd (params, handleError) {
		return HTTP.POST(API_GENERATE(API.POTENTIAL_CLIENTS_ADD), params, handleError);
	}
	//意向-删除
	intentionDel (params, handleError) {
		return HTTP.POST(API_GENERATE(API.POTENTIAL_CLIENTS_DELETE), params, handleError);
	}

	//批次关联-新增
	mapAdd (params, handleError) {
		return HTTP.POST(this.apiList.orderMapAdd, params, handleError)
	}
	//批次关联-删除
	mapDel (params, handleError) {
		return HTTP.POST(this.apiList.orderMapDel, params, handleError)
	}
	//批次关联-列表
	getMapedList (params, handleError) {
		return HTTP.POST(this.apiList.orderMapedList, params, handleError)
	}
	//批次关联-可关联列表
	getCanMapList (params, handleError) {
		return HTTP.POST(this.apiList.orderCanMapList, params, handleError)
	}

	//获取代理供应商
	getSupplier (params = {}, handleError) {
		return HTTP.POST(API_GENERATE(API.AGENT_GET_SUPPLIER), params, handleError);
	}

	//订单授信
	orderTrust (params = {}, handleError) {
		return HTTP.POST(API_GENERATE(API.ORDER_TRUST_LIST), params, handleError);
	}

	//获取客户资金
	getCustomerFunds (params = {}, handleError) {
		return HTTP.POST(API_GENERATE(API.GET_CUSTOMER_FUNDS), params, handleError);
	}

	//授信验证
	orderCreditCheck (params, handleError) {
		return HTTP.POST(API_GENERATE(API.ORDER_CREDIT_CHECK), params, handleError);
	}

	//泉化获取框架地址类型
	getFrameAddress (params, handleError) {
		return HTTP.POST(API_GENERATE(API.ORDER_ADDRESS_LIST), params, handleError);
	}

	//长约框架-商品总量/商品剩余
	executeProductInfo (params, handleError) {
		return HTTP.POST(API_GENERATE(API.ORDER_EXECUTE_PLAN), params, handleError);
	}

	//泉化获取客户优惠和暂定价
	getOrderOtherPrice (params, handleError) {
		return HTTP.POST(API_GENERATE(API.ORDER_OTHER_PRICE), params, handleError);
	}
}

module.exports = new OrderAPIService();


